package com.ruoyi.project.notice.type.service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.notice.type.domain.NoticeType;
import com.ruoyi.project.notice.type.mapper.NoticeTypeMapper;
import com.ruoyi.project.system.notice.mapper.NoticeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeTypeServiceImpl  implements  NoticeTypeService {

    @Autowired
    private NoticeTypeMapper noticeTypeMapper;

    @Override
    public List<NoticeType> findMore(NoticeType noticeType) {
        return noticeTypeMapper.selectMore(noticeType);
    }

    //检验公告的唯一性
    @Override
    public String checkTypeNameUnique(NoticeType noticeType) {

        NoticeType  type=  noticeTypeMapper.selectOne(noticeType);
        //不唯一
        if(type!=null){
            return UserConstants.TYPE__NAME_NOT_UNIQUE;
        }
        //唯一
        return UserConstants.TYPE_NAME_UNIQUE;
    }

    @Override
    public int insertType(NoticeType noticeType) {

        return noticeTypeMapper.insert(noticeType);
    }

    @Override
    public NoticeType selectTypeById(Long tid) {
        return noticeTypeMapper.selectbyId(tid);
    }

    @Override
    public int updateType(NoticeType noticeType) {
        return noticeTypeMapper.update(noticeType);
    }

    @Override
    public int deleteTypeByIds(String ids) {
        Long[] postIds = Convert.toLongArray(ids);

        return noticeTypeMapper.deleteByIds(postIds);
    }
}
